<template>
  <scroll-view class="coupon-scroll" scroll-x="true">
    <view class="coupon-item" v-for="(item, index) in couponList" :key="index">
      <view class="coupon-content">
        <view class="coupon-info">
          <view class="info-inner">
            <view class="price">
              <text
                v-if="item.discount_type != 1"
                :style="{ color: priceColor }"
                >￥</text
              >
              <text
                v-if="item.discount_type != 1"
                :style="{ color: priceColor }"
                >{{ item.sub_price }}</text
              >
              <text
                v-if="item.discount_type == 1"
                :style="{ color: priceColor, fontSize: '54rpx' }"
                >{{ item.discount }}折</text
              >
            </view>
            <view class="coupon-date" :style="{ color: infoColor }">{{
              item.expire_type != 1
                ? item.begintime + "-" + item.endtime
                : "领取" + item.expire_day + "天后失效"
            }}</view>
          </view>
        </view>

        <view
          class="coupon-receive"
          @click.stop="toGetCoupon(item)"
          :class="item.is_receive == 1 ? 'has-receive' : ''"
          :style="{ borderColor: colorConfig.breakLine }"
        >
          <view class="receive-inner">
            <view class="receive-text" :style="{ color: btnColor }">{{
              item.receive_content
            }}</view>
            <i class="iconfont icon-arrow-right"></i>
          </view>
        </view>
      </view>
      <view class="coupon-bg" :style="{ background: colorConfig.bgColor }">
      </view>
    </view>
  </scroll-view>
</template>

<script>
export default {
  props: {
    propsData: {
      type: Object,
      default: () => {
        return {};
      },
    },
    couponList: {
      type: Array,
      default: [],
    },
  },

  computed: {
    colorConfig() {
      return this.propsData.params.colorConfig;
    },
    priceColor() {
      return this.propsData.params.colorConfig.priceColor;
    },
    infoColor() {
      return this.propsData.params.colorConfig.infoColor;
    },
    btnColor() {
      return this.propsData.params.colorConfig.btnColor;
    },
  },

  methods: {
    toGetCoupon(item) {
      if (item.is_receive != 0) return;
      this.$emit("toGetCoupon", { item });
    },
  },
};
</script>

<style scoped lang="scss">
.coupon-scroll {
  width: 93.6%;
  white-space: nowrap;
  margin: 0 auto;
  .coupon-item {
    width: 48.43%;
    position: relative;
    height: 23.534vw;
    display: inline-block;
    margin-right: 3.2vw;
    .coupon-content {
      width: 95.88%;
      height: 92.39%;
      position: absolute;
      left: 0;
      top: 0;
      z-index: 11;
      display: flex;
      align-items: center;
      justify-content: space-between;
      background: #ffffff;
      border: 1px solid #666666;
      .coupon-info {
        width: 63.53%;
        height: 100%;
        display: flex;
        justify-content: center;
        align-items: center;
        .info-inner {
          flex: 1;
          display: flex;
          flex-direction: column;
          align-items: center;
        }
        .price {
          display: flex;
          align-items: baseline;
          line-height: 1;
          text:first-child {
            font-size: 32rpx;
            color: #ec2827;
          }
          text:last-child {
            color: #ec2827;
            font-size: 60rpx;
            font-weight: bold;
          }
        }
        .coupon-date {
          font-size: 24rpx;
          font-family: PingFang SC;
          font-weight: 400;
          color: #ffffff;
          margin-top: 25rpx;
          max-width: 61.33%;
          overflow: hidden;
          text-overflow: ellipsis;
          white-space: nowrap;
        }
      }

      .coupon-receive {
        width: 40.49%;
        height: 55.29%;
        display: flex;
        justify-content: center;
        align-items: center;
        border-left: 1px solid #cccccc;
        .receive-inner {
          display: flex;
          justify-content: center;
          align-items: center;
          .receive-text {
            width: 50rpx;
            font-size: 24rpx;
            font-family: PingFang SC;
            font-weight: 400;
            color: #404040;
            white-space: pre-wrap;
            word-wrap: break-word;
            word-break: break-all;
          }
          .iconfont {
            font-size: 22rpx;
            color: #cccccc;
          }
        }
      }
      .has-receive {
        .receive-inner {
          .receive-text {
            width: 72rpx;
            color: #cccccc !important;
          }
        }
      }
    }
    .coupon-bg {
      width: 95.88%;
      height: 92.39%;
      position: absolute;
      right: 0;
      bottom: 0;
      z-index: 10;
    }
  }
  .coupon-item:last-child {
    margin-right: 0;
  }
}
</style>
